import {Component, OnInit, OnDestroy} from '@angular/core';
import { FormGroup, FormBuilder, Validators } from '@angular/forms';

@Component({
  selector: 'app-login',
  templateUrl: './login.component.html',
  styleUrls: ['./login.component.scss']
})
export class LoginComponent implements OnInit ,OnDestroy{
  validateForm: FormGroup;
  loading = false;
  get userName() {
    return this.validateForm.controls.userName;
  }

  get password() {
    return this.validateForm.controls.password;
  }

  submitForm() {
    this.userName.markAsDirty();
    this.password.markAsDirty();
    if (this.userName.invalid || this.password.invalid) {
      return;
    }
    console.log("user name, this.password", this.userName.value, this.password.value);
    //http请求
    this.loading = true;
  }

  constructor(private fb: FormBuilder) {

  }

  ngOnInit() {
    this.validateForm = this.fb.group({
      userName: [ null, [ Validators.required ] ],
      password: [ null, [ Validators.required ] ],
    });
  }


  ngOnDestroy(): void {

  }
}
